********************************************************************************
** 	TITLE:		pooled_whole_contact_networks                                 ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       Various election studies                                      **
**  DATE:	    October 2022 						                          **	
**  VERSION:	Stata 16		                                              **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "pooled_whole_contact_networks", replace

* Open dataset

use "merge_contact_networks_full.dta", clear

* Identify US state presidential elections

gen stelec = 1 if strpos(study_id, "ANES-S") > 0

* Standardized knowledge

egen study_group = group(study_id)
sort study_group
by study_group: egen knowledge_mean = mean(knowledge)
by study_group: egen knowledge_sd  = sd(knowledge)
by study_group: gen  knowledge_std = (knowledge - knowledge_mean)/knowledge_sd


****************************
** COMPETITIVENESS: WHOLE **
****************************

* Bare-bones models for competitiveness

eststo: mixed forecast enep_w i.wishful_3pts time i.type2 i.system2 if stelec!= 1 || region: || study_id: , mle var
estimates store m1

eststo: mixed forecast margin_w i.wishful_3pts time i.type2 i.system2 if stelec!= 1 || region: || study_id: , mle var
estimates store m2

eststo: mixed forecast pollmar i.misleading i.wishful_3pts time i.type2 i.system2 if stelec!= 1 || region: || study_id: , mle var
estimates store m3

label variable forecast " "

esttab using "pooled_competitiveness_w.tex", wide drop(0.misleading) refcat(enep_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.type2 "\textbf{\textit{Election type}}" 0.system2 "\textbf{\textit{Election system}}" 1.misleading "\textbf{\textit{Misleading polls?}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("ENEP" "Vote margin" "Poll margin") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" enep_w "\hspace{1em} ENEP" margin_w "\hspace{1em} Vote margin" pollmar "\hspace{1em} Poll margin" 1.misleading "\hspace{1em} Yes" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.type2 "\hspace{1em} Legislative (R)" 1.type2 "\hspace{1em} Executive" 0.system2 "\hspace{1em} Proportional (R)" 1.system2 "\hspace{1em} Majoritarian") title("Competitiveness and citizens' forecasting ability, regional/national-level expectations") order(1.wishful_3pts 2.wishful_3pts 3.wishful_3pts time enep_w margin_w pollmar 1.misleading 0.type2 1.type2 0.system2 1.system2) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Predictive margins for margin of victory

estimates restore m2

margins, at(margin_w=0) atmeans
margins, at(margin_w=30) atmeans

estimates restore m3

margins, at(pollmar=0) atmeans
margins, at(pollmar=30) atmeans

estimates restore m2

qui margins, at(margin_w=(0(2)30))

marginsplot, recast(line) recastci(rline) ciopts(lpat(dash) col(black)) ylabel(0(.2)1, labsize(medium) nogrid angle(horizontal) format(%5.1f)) plotopts(lcolor(black) mcolor(black)) xlabel(0(5)30, labsize(medium)) xtitle("Margin of victory", size(medium) margin(t=5)) ytitle("Linear prediction", size(medium) margin(r=5)) title("") graphregion(color(white)) legend(off) saving("margin_w.gph", replace)

estimates restore m3

qui margins, at(pollmar=(0(2)30))

marginsplot, recast(line) recastci(rline) ciopts(lpat(dash) col(black)) ylabel(0(.2)1, labsize(medium) nogrid angle(horizontal) format(%5.1f)) plotopts(lcolor(black) mcolor(black)) xlabel(0(5)30, labsize(medium)) xtitle("Poll margin", size(medium) margin(t=5)) ytitle("Linear prediction", size(medium) margin(r=5)) title("") graphregion(color(white)) legend(off) saving("pollmar_w.gph", replace)


**********************************************
** INTERACTIONS WITH COMPETITIVENESS: WHOLE **
**********************************************

* Wishful thinking and competitiveness

eststo: mixed forecast i.wishful_3pts##c.margin_w i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.wishful_3pts , mle var

label variable forecast " "

esttab using "pooled_wishful_margin_w.tex", wide drop(0.postsecondary 0.male 1.wishful_3pts#c.margin_w) refcat(margin_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.system2 "\textbf{\textit{Election system}}" 2.wishful_3pts#c.margin_w "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Wishful thinking") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_w "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.system2 "\hspace{1em} Proportional (R)" 1.system2 "\hspace{1em} Majoritarian" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 2.wishful_3pts#c.margin_w "\hspace{1em} No preference $\times$ Margin" 3.wishful_3pts#c.margin_w "\hspace{1em} Winner preference $\times$ Margin") title("\textit{Wishful thinking $\times$ Margin of victory} interaction, regional/national-level expectations") order(1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_w 0.system2 1.system2 2.wishful_3pts#c.margin_w 3.wishful_3pts#c.margin_w 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Discussion and competitiveness

eststo: mixed forecast i.discussion_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.discussion_3pts , mle var

label variable forecast " "

esttab using "pooled_discussion_margin_w.tex", wide drop(0.postsecondary 0.male 0.discussion_3pts#c.margin_w) refcat(margin_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.discussion_3pts "\textbf{\textit{Political discussion}}" 0.system2 "\textbf{\textit{Election system}}" 1.discussion_3pts#c.margin_w "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Discussion") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_w "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.system2 "\hspace{1em} Proportional (R)" 1.system2 "\hspace{1em} Majoritarian" 0.discussion_3pts "\hspace{1em} Low (R)" 1.discussion_3pts "\hspace{1em} Medium" 2.discussion_3pts "\hspace{1em} High" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.discussion_3pts#c.margin_w "\hspace{1em} Medium $\times$ Margin" 2.discussion_3pts#c.margin_w "\hspace{1em} High $\times$ Margin") title("\textit{Political discussion $\times$ Margin of victory} interaction, regional/national-level expectations") order(0.discussion_3pts 1.discussion_3pts 2.discussion_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_w 0.system2 1.system2 1.discussion_3pts#c.margin_w 2.discussion_3pts#c.margin_w 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Disagreement and competitiveness

eststo: mixed forecast i.disagreement_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.disagreement_3pts , mle var

label variable forecast " "

esttab using "pooled_disagreement_margin_w.tex", wide drop(0.postsecondary 0.male 0.disagreement_3pts#c.margin_w) refcat(margin_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.disagreement_3pts "\textbf{\textit{Disagreement}}" 0.system2 "\textbf{\textit{Election system}}" 1.disagreement_3pts#c.margin_w "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Disagreement") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_w "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.system2 "\hspace{1em} Proportional (R)" 1.system2 "\hspace{1em} Majoritarian" 0.disagreement_3pts "\hspace{1em} Low (R)" 1.disagreement_3pts "\hspace{1em} Medium" 2.disagreement_3pts "\hspace{1em} High" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.disagreement_3pts#c.margin_w "\hspace{1em} Medium $\times$ Margin" 2.disagreement_3pts#c.margin_w "\hspace{1em} High $\times$ Margin") title("\textit{Disagreement $\times$ Margin of victory} interaction, regional/national-level expectations") order(0.disagreement_3pts 1.disagreement_3pts 2.disagreement_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_w 0.system2 1.system2 1.disagreement_3pts#c.margin_w 2.disagreement_3pts#c.margin_w 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Network size and competitiveness

eststo: mixed forecast i.size_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.size_3pts , mle var

label variable forecast " "

esttab using "pooled_size_margin_w.tex", wide drop(0.postsecondary 0.male 0.size_3pts#c.margin_w) refcat(margin_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.size_3pts "\textbf{\textit{Network size}}" 0.system2 "\textbf{\textit{Election system}}" 1.size_3pts#c.margin_w "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Network size") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_w "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.system2 "\hspace{1em} Proportional (R)" 1.system2 "\hspace{1em} Majoritarian" 0.size_3pts "\hspace{1em} Small (R)" 1.size_3pts "\hspace{1em} Medium" 2.size_3pts "\hspace{1em} Large" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.size_3pts#c.margin_w "\hspace{1em} Medium $\times$ Margin" 2.size_3pts#c.margin_w "\hspace{1em} Large $\times$ Margin") title("\textit{Network size $\times$ Margin of victory} interaction, regional/national-level expectations") order(0.size_3pts 1.size_3pts 2.size_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_w 0.system2 1.system2 1.size_3pts#c.margin_w 2.size_3pts#c.margin_w 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Network expertise and competitiveness

eststo: mixed forecast c.expertise_4pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time if stelec!= 1 || region: || study_id: expertise_4pts , mle var

label variable forecast " "

esttab using "pooled_expertise_margin_w.tex", wide drop(0.postsecondary 0.male) refcat(margin_w "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" expertise_4pts "\textbf{\textit{Network expertise}}" 0.system2 "\textbf{\textit{Election system}}" c.expertise_4pts#c.margin_w "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Network expertise") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_w "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" expertise_4pts "\hspace{1em} Expertise" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" c.expertise_4pts#c.margin_w "\hspace{1em} Expertise $\times$ Margin") title("\textit{Network expertise $\times$ Margin of victory} interaction, regional/national-level expectations") order(expertise_4pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_w c.expertise_4pts#c.margin_w 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

*******************************************************************************************
** Interaction of wishful thinking and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.wishful_3pts##c.margin_w i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.wishful_3pts , mle var

mgen if wishful_3pts == 1, at(margin_w=(0(2)30)) stub(A) replace // Predictive margins for loser preference
mgen if wishful_3pts == 2, at(margin_w=(0(2)30)) stub(B) replace // Predictive margins for no preference
mgen if wishful_3pts == 3, at(margin_w=(0(2)30)) stub(C) replace // Predictive margins for winner preference

lab var Amargin "Loser preference" // Add labels for graph legend
lab var	Bmargin "No preference"
lab var	Cmargin "Winner preference"

gen ASig1 = Amargin // Create variable for significance information of group differences
gen BSig1 = Bmargin
gen CSig1 = Cmargin
lab var ASig1 "A"
lab var BSig1 "B"
lab var	CSig1 "C"

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig1 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig1 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Winner–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_loser_wishful_margin_w.gph", replace) // Winner vs Loser

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig1 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig1 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("Winner–None", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "No preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_no_wishful_margin_w.gph", replace) // Winner vs None

twoway (rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig1 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig1 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("None–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "No preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("no_loser_wishful_margin_w.gph", replace) // None vs Loser

graph combine winner_loser_wishful_margin_w.gph winner_no_wishful_margin_w.gph no_loser_wishful_margin_w.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("wishful_margin_w.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w >= 0 & margin_w <= 5 || region: || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin1_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 5 & margin_w <= 10 || region: || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin2_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 10 & margin_w <= 15 || region: || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin3_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 15 || region: || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin4_w.gph", replace

graph combine wishful_margin1_w.gph wishful_margin2_w.gph wishful_margin3_w.gph wishful_margin4_w.gph, row(2) saving("wishful_margin_1234_w.gph", replace)

*******************************************************************************************
** Interaction of wishful thinking and poll margin (Ordinal X Continuous interaction)

mixed forecast i.wishful_3pts##c.pollmar i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.wishful_3pts , mle var

mgen if wishful_3pts == 1, at(pollmar=(0(2)30)) stub(A) replace // Predictive margins for loser preference
mgen if wishful_3pts == 2, at(pollmar=(0(2)30)) stub(B) replace // Predictive margins for no preference
mgen if wishful_3pts == 3, at(pollmar=(0(2)30)) stub(C) replace // Predictive margins for winner preference

lab var Amargin "Loser preference" // Add labels for graph legend
lab var	Bmargin "No preference"
lab var	Cmargin "Winner preference"

gen ASig2 = Amargin // Create variable for significance information of group differences
gen BSig2 = Bmargin
gen CSig2 = Cmargin
lab var ASig2 "A"
lab var BSig2 "B"
lab var	CSig2 "C"

twoway (rline Cll Cul Cpollmar, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Apollmar, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig2 Cpollmar, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig2 Apollmar, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Winner–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_loser_wishful_pollmar.gph", replace) // Winner vs Loser

twoway (rline Cll Cul Cpollmar, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bpollmar, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig2 Cpollmar, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig2 Bpollmar, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("Winner–None", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "No preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_no_wishful_pollmar.gph", replace) // Winner vs None

twoway (rline Bll Bul Bpollmar, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Apollmar, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig2 Bpollmar, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig2 Apollmar, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("None–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "No preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("no_loser_wishful_pollmar.gph", replace) // None vs Loser

graph combine winner_loser_wishful_pollmar.gph winner_no_wishful_pollmar.gph no_loser_wishful_pollmar.gph, l1("Linear prediction", size(huge)) b1("Poll margin", size(huge) margin(l=9)) row(1) saving("wishful_pollmar.gph", replace)

graph display, ysize(4) xsize(12)

* By level of poll margin

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & pollmar >= 0 & pollmar <= 5 || region: || study_id: , reml var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_pollmar1_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & pollmar > 5 & pollmar <= 10 || region: || study_id: , reml var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_pollmar2_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & pollmar > 10 & pollmar <= 15 || region: || study_id: , reml var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_pollmar3_w.gph", replace

mixed forecast i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & pollmar > 15 || region: || study_id: , reml var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_pollmar4_w.gph", replace

graph combine wishful_pollmar1_w.gph wishful_pollmar2_w.gph wishful_pollmar3_w.gph wishful_pollmar4_w.gph, row(2) saving("wishful_pollmar_1234_w.gph", replace)

*************************************************************************************
** Interaction of discussion and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.discussion_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.discussion_3pts , mle var

mgen if discussion_3pts == 0, at(margin_w=(0(2)30)) stub(A) replace // Predictive margins for low discussion
mgen if discussion_3pts == 1, at(margin_w=(0(2)30)) stub(B) replace // Predictive margins for medium discussion
mgen if discussion_3pts == 2, at(margin_w=(0(2)30)) stub(C) replace // Predictive margins for high discussion

lab var Amargin "Low discussion" // Add labels for graph legend
lab var	Bmargin "Medium discussion"
lab var	Cmargin "High discussion"

gen ASig3 = Amargin // Create variable for significance information of group differences
gen BSig3 = Bmargin
gen CSig3 = Cmargin
lab var ASig3 "A"
lab var BSig3 "B"
lab var	CSig3 "C"

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig3 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig3 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("High–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High discussion" 4 "Low discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_low_discussion_margin_w.gph", replace) // High vs Low

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig3 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig3 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("High–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High discussion" 4 "Medium discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_medium_discussion_margin_w.gph", replace) // High vs Medium

twoway (rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig3 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig3 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium discussion" 4 "Low discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_low_discussion_margin_w.gph", replace) // Medium vs Low

graph combine high_low_discussion_margin_w.gph high_medium_discussion_margin_w.gph medium_low_discussion_margin_w.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("discussion_margin_w.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w >= 0 & margin_w <= 5 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin1_w.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 5 & margin_w <= 10 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin2_w.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 10 & margin_w <= 15 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin3_w.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 15 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin4_w.gph", replace

graph combine discussion_margin1_w.gph discussion_margin2_w.gph discussion_margin3_w.gph discussion_margin4_w.gph, row(2) saving("discussion_margin_1234_w.gph", replace)

* By partisan preference

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful1_w.gph", replace

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful2_w.gph", replace

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful3_w.gph", replace

graph combine discussion_wishful1_w.gph discussion_wishful2_w.gph discussion_wishful3_w.gph, row(1) saving("discussion_wishful_123_w.gph", replace)

graph display, ysize(4) xsize(9)

***************************************************************************************
** Interaction of disagreement and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.disagreement_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.disagreement_3pts , mle var

mgen if disagreement_3pts == 0, at(margin_w=(0(2)30)) stub(A) replace // Predictive margins for low disagreement
mgen if disagreement_3pts == 1, at(margin_w=(0(2)30)) stub(B) replace // Predictive margins for medium disagreement
mgen if disagreement_3pts == 2, at(margin_w=(0(2)30)) stub(C) replace // Predictive margins for high disagreement

lab var Amargin "Low disagreement" // Add labels for graph legend
lab var	Bmargin "Medium disagreement"
lab var	Cmargin "High disagreement"

gen ASig4 = Amargin // Create variable for significance information of group differences
gen BSig4 = Bmargin
gen CSig4 = Cmargin
lab var ASig4 "A"
lab var BSig4 "B"
lab var	CSig4 "C"

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig4 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig4 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("High–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High disagreement" 4 "Low disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_low_disagreement_margin_w.gph", replace) // High vs Low

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig4 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig4 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("High–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High disagreement" 4 "Medium disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_medium_disagreement_margin_w.gph", replace) // High vs Medium

twoway (rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig4 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig4 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium disagreement" 4 "Low disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_low_disagreement_margin_w.gph", replace) // Medium vs Low

graph combine high_low_disagreement_margin_w.gph high_medium_disagreement_margin_w.gph medium_low_disagreement_margin_w.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("disagreement_margin_w.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w >= 0 & margin_w <= 5 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin1_w.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 5 & margin_w <= 10 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin2_w.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 10 & margin_w <= 15 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin3_w.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 15 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin4_w.gph", replace

graph combine disagreement_margin1_w.gph disagreement_margin2_w.gph disagreement_margin3_w.gph disagreement_margin4_w.gph, row(2) saving("disagreement_margin_1234_w.gph", replace)

* By partisan preference

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful1_w.gph", replace

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful2_w.gph", replace

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful3_w.gph", replace

graph combine disagreement_wishful1_w.gph disagreement_wishful2_w.gph disagreement_wishful3_w.gph, row(1) saving("disagreement_wishful_123_w.gph", replace)

graph display, ysize(4) xsize(9)

*******************************************************************************
** Interaction of size and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.size_3pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 || region: || study_id: R.size_3pts , mle var

mgen if size_3pts == 0, at(margin_w=(0(2)30)) stub(A) replace // Predictive margins for small network
mgen if size_3pts == 1, at(margin_w=(0(2)30)) stub(B) replace // Predictive margins for medium network
mgen if size_3pts == 2, at(margin_w=(0(2)30)) stub(C) replace // Predictive margins for large network

lab var Amargin "Small network" // Add labels for graph legend
lab var	Bmargin "Medium network"
lab var	Cmargin "Large network"

gen ASig5 = Amargin // Create variable for significance information of group differences
gen BSig5 = Bmargin
gen CSig5 = Cmargin
lab var ASig5 "A"
lab var BSig5 "B"
lab var	CSig5 "C"

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig5 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig5 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Large–Small", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Large" 4 "Small") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("large_small_size_margin_w.gph", replace) // Large vs Small

twoway (rline Cll Cul Cmargin_w, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig5 Cmargin_w, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig5 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("Large–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Large" 4 "Medium") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("large_medium_size_margin_w.gph", replace) // Large vs Medium

twoway (rline Bll Bul Bmargin_w, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_w, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig5 Bmargin_w, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig5 Amargin_w, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Small", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium discussion" 4 "Small discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_small_size_margin_w.gph", replace) // Medium vs Small

graph combine large_small_size_margin_w.gph large_medium_size_margin_w.gph medium_small_size_margin_w.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("size_margin_w.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w >= 0 & margin_w <= 5 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin1_w.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 5 & margin_w <= 10 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin2_w.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 10 & margin_w <= 15 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin3_w.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 if stelec!= 1 & margin_w > 15 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin4_w.gph", replace

graph combine size_margin1_w.gph size_margin2_w.gph size_margin3_w.gph size_margin4_w.gph, row(2) saving("size_margin_1234_w.gph", replace)

* By partisan preference

mixed forecast i.size_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 1 || region: || study_id: , reml var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful1_w.gph", replace

mixed forecast i.size_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful2_w.gph", replace

mixed forecast i.size_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful3_w.gph", replace

graph combine size_wishful1_w.gph size_wishful2_w.gph size_wishful3_w.gph, row(1) saving("size_wishful_123_w.gph", replace)

graph display, ysize(4) xsize(9)

***************************************************************************************
** Interaction of expertise and margin of victory (Continuous X Continuous interaction)

mixed forecast c.expertise_4pts##c.margin_w i.wishful_3pts i.postsecondary age2 i.male time if stelec!= 1 || region: || study_id: expertise_4pts , mle var

qui margins, at(expertise_4pts=(0 3) margin_w=(0(2)30))

marginsplot, title("") x(margin_w) recastci(rline) ci1opts(lpat(dash) col(red*1.2%30)) ci2opts(lpat(dash) col(green%30)) ylabel(0 1, labsize(large) nogrid angle(horizontal) format(%5.0f)) plot1opts(lcolor(red*1.2) lpattern(solid) msym(none)) plot2opts(lcolor(green) lpattern(solid) msym(none)) xlabel(0 30, labsize(large)) xtitle("Margin of victory", size(large) margin(t=5)) ytitle("Linear prediction", size(large) margin(r=5 b=3)) legend(size(medsmall)) legend(order(3 "No expertise" 4 "High expertise") pos(6) col(2) size(medlarge) symxsize(8) region(lstyle(none))) legend(region(lcolor(white))) legend(off) graphregion(color(white)) saving("expertise_margin_w.gph", replace) // Plot of ideal types

graph display, ysize(4) xsize(5)

* By partisan preference

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_w if stelec!= 1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful1_w.gph", replace

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_w if stelec!= 1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful2_w.gph", replace

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_w if stelec!= 1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful3_w.gph", replace

graph combine expertise_wishful1_w.gph expertise_wishful2_w.gph expertise_wishful3_w.gph, row(1) saving("expertise_wishful_123_w.gph", replace)

graph display, ysize(4) xsize(9)


***************************************************
** INTERACTIONS BETWEEN NETWORK VARIABLES: WHOLE **
***************************************************

* Discussion × Disagreement interaction

mixed forecast i.discussion_3pts##i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 || region: || study_id: , mle var

qui margins, at(disagreement_3pts=(0 2) discussion_3pts=(0(1)2))

marginsplot, x(discussion_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0 "Low" 1 "Medium" 2 "High", labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Low disagreement" 4 "High disagreement")) title("(a) Discussion × Disagreement", size(vlarge) margin(b=3 l=12)) saving("discussion_disagreement_w.gph", replace)

* Discussion × Size interaction

mixed forecast i.discussion_3pts##i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time i.system2 margin_w if stelec!= 1 || region: || study_id: , mle var

qui margins, at(size_3pts=(0 2) discussion_3pts=(0(1)2))

marginsplot, x(discussion_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0 "Low" 1 "Medium" 2 "High", labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Small network" 4 "Large network")) title("(b) Discussion × Size", size(vlarge) margin(b=3 l=12)) saving("discussion_size_w.gph", replace)

* Discussion × Expertise interaction

mixed forecast c.discussion##c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male time margin_w if stelec!= 1 || region: || study_id: , mle var

qui margins, at(expertise_4pts=(0 3) discussion=(0(1)7))

marginsplot, x(discussion) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0(1)7, labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency (days/week)", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Low expertise" 4 "High expertise")) title("(c) Discussion × Expertise", size(vlarge) margin(b=3 l=12)) saving("discussion_expertise_w.gph", replace)

* Disagreement × Size interaction

mixed forecast i.disagreement_3pts##i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time margin_w if stelec!= 1 || region: || study_id: , mle var

qui margins, at(size_3pts=(0 2) disagreement_3pts=(0(1)2))

marginsplot, x(disagreement_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0(1)2, labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Disagreement frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Small network" 4 "Large network")) title("(d) Disagreement × Size", size(vlarge) margin(b=3 l=12)) saving("disagreement_size_w.gph", replace)

* Combine graphs

graph combine discussion_disagreement_w.gph discussion_size_w.gph, row(1) saving("interactions_contact_networks_w1.gph", replace)

graph display, ysize(7) xsize(12)

graph combine discussion_expertise_w.gph disagreement_size_w.gph, row(1) saving("interactions_contact_networks_w2.gph", replace)

graph display, ysize(7) xsize(12)

log close